package com.sy.core.service;

import com.sy.core.mapper.SyArticleMapper;
import com.sy.core.model.SyArticle;
import com.sy.core.util.BaseUUID;
import com.sy.core.web.BaseCtl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ArticleService extends BaseCtl {
    @Autowired
    SyArticleMapper syArticleMapper;

    public List<Map<String,Object>> queryList(SyArticle syArticle) {
        return syArticleMapper.queryList(syArticle);
    }

    public String save(SyArticle syArticle) {
        String pk = syArticle.getPk();
        if(StringUtils.isNotBlank(pk)){
            syArticleMapper.updateByPrimaryKeySelective(syArticle);
        }else{
            pk= BaseUUID.getUUID();
            syArticle.setPk(pk);
            syArticle.setC1(getTime());
            syArticle.setC2(getLoginUser().getPk());
            syArticleMapper.insertSelective(syArticle);
        }
        return pk;
    }

    public Map<String, Object> queryOne(String pk) {
        return syArticleMapper.queryOne(pk);
    }

    public Integer batchDel(String pks) {
        return syArticleMapper.batchDel(pks);
    }

    public List<String> queryArticleType(SyArticle syArticle) {
        return syArticleMapper.queryArticleType(syArticle);
    }
}
